package cn.bellychang.leetcode.question876;

/**
 * @author ChangLiang
 * @date 2021/1/28
 */
public class Solution2 {

    public ListNode middleNode(ListNode head) {
        // 使用循环 循环不变量
        // 两个指针

        ListNode fast = head;
        ListNode slow = head;
        while (fast != null) {
            fast = fast.next;
            if (fast != null) {
                fast = fast.next;
                slow = slow.next;
            } else {
                break;
            }
        }
        return slow;
    }
}
